﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/AdminCP/Views/Shared/ViewMasterPage1.Master"
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <table id="list">
    </table>
    <div id="pager">
    </div>
    <script type="text/javascript">
        $(function () {
            var grid = $("#list");
            grid.jqGrid({
                url: '<%= Url.Action("Get_List_GiaoPhan", "MucVu",null) %>',
                datatype: 'json',
                mtype: 'POST',
                colNames: [
                    '#',
                    'Tên Giáo Phận',
                    'Địa Chỉ',
                    'Điện Thoại'
                    ],
                colModel: [
                //{ name: 'Id', index: 'Id', width: 40, align: 'center', sortable: true, key: true, searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge']} },
                //{ name: 'Name', index: 'Name', width: 150, align: 'left', sortable: true, searchoptions: { sopt: ['cn','bw', 'bn', 'nc']} },
                {name: 'MAGIAOPHAN', index: 'MAGIAOPHAN', width: 150, align: 'left', sortable: true, hidden: true, key: true, searchoptions: { sopt: ['cn','bw', 'bn', 'nc']} },
                { name: 'TENGIAOPHAN', index: 'TENGIAOPHAN', width: 150, align: 'left', sortable: true, searchoptions: { sopt: ['cn','bw', 'bn', 'nc']} },
                { name: 'DIACHI', index: 'DIACHI', width: 150, align: 'left', sortable: true, searchoptions: { sopt: ['cn','bw', 'bn', 'nc']} },
                { name: 'DIENTHOAI', index: 'DIENTHOAI', width: 150, align: 'left', sortable: true, searchoptions: { sopt: ['cn','bw', 'bn', 'nc']} }
                ],
                jsonReader: {
                    root: "rows",
                    page: "page",
                    total: "total",
                    records: "records",
                    repeatitems: false,
                    userdata: "userdata"
                },

                multiselect: true,
                multiboxonly: true,
                rownumbers: true,
                pager: $("#pager"),
                toppager: true,
                autowidth: true,
                rowNum: 15,
                rowList: [10, 15, 20, 30, 60],
                sortname: 'TENGIAOPHAN',
                sortorder: 'asc',
                viewrecords: true,
                height: 'auto',
                caption: '',
                beforeRequest: function () {
                    $('.jqgrid-overlay').fadeIn();
                },
                gridComplete: function () {
                    $('.jqgrid-overlay').fadeOut();
                }
            })
        .navGrid('#pager', { view: false, del: false, add: false, edit: false, searchtext: 'Tìm kiếm', cloneToTop: true },
                {}, // default settings for edit
                {}, // default settings for add
                {}, // delete instead that del:false we need this
                {closeOnEscape: true, multipleSearch: true, closeAfterSearch: true }, // search options
                {} /* view parameters*/
        );

            grid.jqGrid('navGrid', '#ptoolbar', { del: false, add: false, edit: false, search: false });
            grid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false });


            grid.jqGrid('navButtonAdd', '#' + grid[0].id + '_toppager_left', { // "#list_toppager_left"
                caption: "",
                title: "Thêm mới Giáo Phận",
                buttonicon: 'ui-icon-plus',
                onClickButton: function () {
                    window.location = '<%=Url.Action("Add_GiaoPhan", "MucVu")%>';
                }
            });

            grid.jqGrid('navButtonAdd', '#' + grid[0].id + '_toppager_left', { // "#list_toppager_left"
                caption: "",
                buttonicon: 'ui-icon-pencil',
                onClickButton: function () {
                    var selrows = grid.getGridParam("selarrrow");
                    if (selrows != null) {
                        if (selrows.length > 1) {
                        }
                        else if (selrows.length == 0) {
                        }
                        else {
                            var url = '<%=Url.Action("Edit_GiaoPhan", "MucVu", new { id="ID" })%>';
                            window.location = url.replace("ID", selrows);
                        }
                    }

                }
            });

            grid.jqGrid('navButtonAdd', '#' + grid[0].id + '_toppager_left', { // "#list_toppager_left"
                caption: "",
                buttonicon: 'ui-icon-trash',
                onClickButton: function () {
                    var selrows = grid.getGridParam("selarrrow");
                    var rows = "";

                    for (var i = 0; i < selrows.length; i++) {
                        if (selrows[i] != null) {
                            if (rows.length <= 0)
                                rows += selrows[i];
                            else
                                rows += "," + selrows[i];
                        }
                    }

                    if (rows.length > 0) {
                        var comfirm = confirm('Do you want to delete?');
                        if (comfirm) {
                            $.post('<%=Url.Action("Delete_GiaoPhan", "MucVu") %>', { id: rows },
                        function (data) {
                            $('#list').trigger("reloadGrid", function () {
                                data;
                            });
                        });
                        }
                    }
                    else {
                    }
                }
            });

            // remove some double elements from one place which we not need double
            var topPagerDiv = $('#' + grid[0].id + '_toppager')[0];         // "#list_toppager"
            $("#edit_" + grid[0].id + "_top", topPagerDiv).remove();        // "#edit_list_top"
            $("#del_" + grid[0].id + "_top", topPagerDiv).remove();         // "#del_list_top"
            $("#search_" + grid[0].id + "_top", topPagerDiv).remove();      // "#search_list_top"
            $("#refresh_" + grid[0].id + "_top", topPagerDiv).remove();     // "#refresh_list_top"
            $("#" + grid[0].id + "_toppager_center", topPagerDiv).remove(); // "#list_toppager_center"
            $(".ui-paging-info", topPagerDiv).remove();

            var bottomPagerDiv = $("div#pager")[0];
            $("#add_" + grid[0].id, bottomPagerDiv).remove();               // "#add_list"

        });
     
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderCss" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderScript" runat="server">
</asp:Content>
